<!DOCTYPE html>
<title>Console Unit Tests</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width">
<link rel="stylesheet" href="https://code.jquery.com/qunit/qunit-2.1.1.css">
<script src="https://code.jquery.com/qunit/qunit-2.1.1.js"></script>

<div id="qunit"></div>
<div id="qunit-fixture"></div>

<script type="text/javascript" src="../../polyfill.js"></script>
<script type="text/javascript">window.console = null;</script>
<script type="text/javascript" src="../console.js"></script>
<script type="text/javascript">

QUnit.test("API", function(assert) {
  assert.equal(typeof console, "object");
  assert.ok(console != null);
  assert.equal(typeof console.log, "function");
  assert.equal(typeof console.debug, "function");
  assert.equal(typeof console.info, "function");
  assert.equal(typeof console.warn, "function");
  assert.equal(typeof console.error, "function");

  assert.equal(typeof console.assert, "function");

  assert.equal(typeof console.count, "function");

  assert.equal(typeof console.time, "function");
  assert.equal(typeof console.timeEnd, "function");

  assert.equal(typeof console.group, "function");
  assert.equal(typeof console.groupEnd, "function");

  assert.equal(typeof console.dir, "function");
  assert.equal(typeof console.dirxml, "function");

  assert.equal(typeof console.trace, "function");
});

QUnit.test("Data types", function(assert) {
  var data = ['"test"', '123', 'true', 'false', 'undefined', 'null'];
  while (data.length) {
    var datum = data.shift();
    var value = eval('value = ' + datum);
    assert.ok(console.log(value) || true, datum);
    assert.ok(console.debug(value) || true, datum);
    assert.ok(console.info(value) || true, datum);
    assert.ok(console.warn(value) || true, datum);
    assert.ok(console.error(value) || true, datum);
  }
});

QUnit.test("Multiple arguments", function(assert) {
  assert.ok(console.log("test", 123, true, false, undefined, null) || true);
  assert.ok(console.debug("test", 123, true, false, undefined, null) || true);
  assert.ok(console.info("test", 123, true, false, undefined, null) || true);
  assert.ok(console.warn("test", 123, true, false, undefined, null) || true);
  assert.ok(console.error("test", 123, true, false, undefined, null) || true);
});

QUnit.test("Cyclic data structures", function(assert) {
  var cyclic_array = [], cyclic_object = {};
  cyclic_array.push(cyclic_array);
  cyclic_object['self'] = cyclic_object;

  assert.ok(console.log(cyclic_array) || true);
  assert.ok(console.log(cyclic_object) || true);
});

QUnit.test("Built-ins and non-JS objects", function(assert) {
  assert.ok(console.log(Math) || true);
  assert.ok(console.log(document) || true);
  assert.ok(console.log(window) || true);
});

QUnit.test("Formatting", function(assert) {
  console.log("%%");
  var data = ['"test"', '123', 'true', 'false', 'undefined', 'null', '{a: 1, b: 2}', 'new Date(0)', 'Math', 'Error', 'document'];
  while (data.length) {
    var datum = data.shift();
    var value = eval('value = ' + datum);
    assert.ok(console.log("string %s", value) || true, datum);
    assert.ok(console.log("integer %d", value) || true, datum);
    assert.ok(console.log("integer %l", value) || true, datum);
    assert.ok(console.log("integer %i", value) || true, datum);
    assert.ok(console.log("float %f", value) || true, datum);
    assert.ok(console.log("object %o", value) || true, datum);
    assert.ok(console.log("other %x", value) || true, datum);
  }
  assert.ok(console.log("%s %d %o", "string", 1234, {a:1, b: 2}, "extra", 1234, {c: 3, d: 4}) || true);
});

QUnit.test("Dir", function(assert) {
  assert.ok(console.dir({}) || true);
  assert.ok(console.dir({a:1, b: 2}) || true);

  assert.ok(console.dirxml({}) || true);
  assert.ok(console.dirxml({a:1, b: 2}) || true);
});

QUnit.test("Assert", function(assert) {
  assert.ok(console.assert(false, "this should fail") || true);
  assert.ok(console.assert(true, "this should pass") || true);
});

QUnit.test("Count", function(assert) {
  assert.ok(console.count() || true);
  assert.ok(console.count() || true);
  assert.ok(console.count("foo") || true);
  assert.ok(console.count("foo") || true);
});

QUnit.test("Time", function(assert) {
  assert.ok(console.time() || true);
  assert.ok(console.timeEnd() || true);
  assert.ok(console.time("foo") || true);
  assert.ok(console.timeEnd("foo") || true);
});

QUnit.test("Trace", function(assert) {
  assert.ok(console.trace() || true);
});

QUnit.test("Group", function(assert) {
  assert.ok(console.log("not in group") || true);
  assert.ok(console.group() || true);
  assert.ok(console.log("in anonymous group") || true);
  assert.ok(console.groupEnd() || true);
  assert.ok(console.group("foo") || true);
  assert.ok(console.log("in group foo") || true);
  assert.ok(console.group("bar") || true);
  assert.ok(console.log("in group foo / bar") || true);
  assert.ok(console.groupEnd() || true);
  assert.ok(console.groupEnd() || true);
  assert.ok(console.log("not in group") || true);
});

QUnit.test("Table", function(assert) {
  assert.ok(console.table([['a', 'b', 'c', 'd'], [1, 2, 3]]) || true);
});

</script>
